package com.dream.keigezhushou.Activity.acty.personal.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;


import com.dream.keigezhushou.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 店铺fragment
 */

public class ShopFragment extends Fragment {

    @BindView(R.id.lv_shop)
    ListView lvShop;
    private View mView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        if (mView == null) {
            mView = LayoutInflater.from(getContext()).inflate(R.layout.layout_shop_fragment, container, false);
        }

        ViewGroup viewGroup = (ViewGroup) mView.getParent();
        if (viewGroup != null) {

            viewGroup.removeView(mView);
        }

        ButterKnife.bind(this, mView);

        initData();
        return mView;
    }

    //初始化数据
    protected void initData(){

        //ListView创建适配器
        lvShop.setAdapter(new shopAdapter(getActivity()));
    }

    public class shopAdapter extends BaseAdapter{

        private Context mContext;
        int c = 5;
        public shopAdapter(Context context) {
            this.mContext = context;
        }

        @Override
        public int getCount() {
            return c;
        }

        @Override
        public Object getItem(int i) {
            return i;
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {

            ViewHolder mHolder = null;
            if (view == null){

                view = LayoutInflater.from(mContext).inflate(R.layout.shop_list_item,null);
                mHolder = new ViewHolder();
                view.setTag(mHolder);
            }else {
                mHolder = (ViewHolder)view.getTag();
            }
            return view;
        }

        class ViewHolder{

        }
    }
}
